#include "Prot.h"
#include "Motor.hpp"
uint32_t SystemTimes = 0;
volatile float id = 0.0f;
volatile float iq = 0.0f;
volatile float engle = 0.0f;
float temp = 0.0005f;
uint8_t dir = 0;
extern Encoder *encoder;
#ifdef CH32
extern "C" void TIM8_UP_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
extern "C" void TIM3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void TIM8_UP_IRQHandler(void)
{
    if (TIM_GetITStatus(TIM8, TIM_IT_Update) != RESET)
    {
        engle = encoder->getDegEncoder();
        setPhashVoltage_t(iq, id, engle);
        TIM_ClearITPendingBit(TIM8, TIM_IT_Update);
    }
}
#endif
#ifdef STM32
extern TIM_HandleTypeDef htim8;
extern "C" void TIM8_UP_TIM13_IRQHandler(void)
{
    if (__HAL_TIM_GET_FLAG(&htim8, TIM_FLAG_UPDATE) != RESET)
    {
        if (__HAL_TIM_GET_IT_SOURCE(&htim8, TIM_IT_UPDATE) != RESET)
        {
            engle = encoder->getDegEncoder();
            setPhashVoltage_t(iq, id, engle);
            __HAL_TIM_CLEAR_IT(&htim8, TIM_IT_UPDATE);
        }
    }
}

#endif

#ifdef AT32
extern "C" void TMR8_OVF_TMR13_IRQHandler(void)
{
    if (tmr_flag_get(TMR8, TMR_OVF_FLAG) != RESET)
    {
        engle = encoder->getDegEncoder();
        setPhashVoltage_t(iq, id, engle);
        tmr_flag_clear(TMR8, TMR_OVF_FLAG);
    }
}
#endif